package com.sskj.aikeeper.hangqing.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.constraint.ConstraintLayout;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sskj.aikeeper.R;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.SpApplication;
import com.sskj.aikeeper.bean.ShareBean;
import com.sskj.aikeeper.presenter.SharePresenter;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ImageUtil;
import com.sskj.lib.Constans;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.util.WXShareUtil;
import com.sskj.lib.widget.BottomDialog;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/07/02
 */
public class ShareActivity extends BaseActivity<SharePresenter> {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.cs_share)
    ConstraintLayout csShare;
    @BindView(R.id.iv_right)
    ImageView ivRight;
    @BindView(R.id.iv_share_logo)
    ImageView ivShareLogo;
    @BindView(R.id.iv_share_title)
    ImageView ivShareTitle;
    @BindView(R.id.iv_qrcode)
    ImageView ivQrcode;

    @Override
    public int getLayoutId() {
        return R.layout.app_activity_share;
    }

    @Override
    public SharePresenter getPresenter() {
        return new SharePresenter();
    }

    @Override
    public void initView() {
        tvTitle.setText(App.INSTANCE.getString(R.string.app_shareActivity1));
        ivRight.setVisibility(View.VISIBLE);
        ivRight.setImageResource(R.mipmap.icon_fenxiang);
        if (Constans.LANGUAGE_EN.equals(SPUtil.get(SPConfig.LANGUAGE, Constans.LANGUAGE_CNA))) {
            ImageUtil.setImage(R.mipmap.icon_logo02_english, ivShareLogo);
        } else if (Constans.LANGUAGE_CNA.equals(SPUtil.get(SPConfig.LANGUAGE, Constans.LANGUAGE_CNA))) {
            ImageUtil.setImage(R.mipmap.icon_logo02, ivShareLogo);
        } else if (Constans.LANGUAGE_TRA.equals(SPUtil.get(SPConfig.LANGUAGE, Constans.LANGUAGE_CNA))) {
            ImageUtil.setImage(R.mipmap.icon_logo02, ivShareLogo);
        }
        ClickUtil.click(300, ivRight, () -> {
            csShare.setDrawingCacheEnabled(true);
            csShare.buildDrawingCache();
            Bitmap bitmap = csShare.getDrawingCache();
            BottomDialog.share(this, tv -> {
                switch (tv) {
                    case Constans.SHARE_WECHAT:
                        WXShareUtil.shareFriendsBitmap(bitmap);
                        break;
                    case Constans.SHARE_PENGYOUQUAN:
                        WXShareUtil.shareQuanBitmap(bitmap);
                        break;
                }
            });
        });
        mPresenter.getShareInfo();

    }

    @Override
    public void initData() {

    }

    public static void start(Context context) {
        Intent intent = new Intent(context, ShareActivity.class);
        context.startActivity(intent);
    }

    public void getShareInfoOK(ShareBean data) {
        if (data == null) {
            return;
        }
        ImageUtil.setImageWithoutCache(data.getQrc(), ivQrcode);
    }
}
